package com.theo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.theo.entity.TripInfo;
import com.theo.mapper.TripInfoMapper;
import com.theo.service.TripInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 方涛
 * @since 2021-02-02
 */
@Service
public class TripInfoServiceImpl extends ServiceImpl<TripInfoMapper, TripInfo> implements TripInfoService {

    @Autowired
    private TripInfoMapper tripInfoMapper;
    @Override
    public int saveTripInfo(TripInfo tripInfo) {
        return tripInfoMapper.insert(tripInfo);
    }

    @Override
    public int deleteTripInfo(Integer id) {
        return tripInfoMapper.deleteById(id);
    }

    @Override
    public int updateTripInfo(TripInfo tripInfo) {
        return tripInfoMapper.updateById(tripInfo);
    }

    @Override
    public TripInfo queryTripInfo(Integer id) {
        return tripInfoMapper.selectById(id);
    }

    @Override
    public List<TripInfo> queryAllTripInfo() {
        QueryWrapper<TripInfo> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("date");
        return tripInfoMapper.selectList(wrapper);
    }

    @Override
    public List<TripInfo> queryAllByDate(String date) {
        QueryWrapper<TripInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("date", date);
        return tripInfoMapper.selectList(wrapper);
    }

    @Override
    public List<TripInfo> queryAllByTripType(Integer type) {
        QueryWrapper<TripInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("trip_type_num", type)
                .orderByDesc("date");
        return tripInfoMapper.selectList(wrapper);
    }

    @Override
    public List<TripInfo> queryAllByLimit(Map<String, Object> map) {
        return tripInfoMapper.queryAllByLimit(map);
    }
}
